package com.versita.domain;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;


/**
 * 
 * @author vmc
 *
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED) // normalize the value
public class User implements Serializable {
    private static final long serialVersionUID = 4875403899493586480L;

    private long userId;
    private String username;
    private String password;

    private UserDetail userDetail;
    private UserLocation userLocation;

    /**
     * @return the userId
     */
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    public long getUserId() {
        return userId;
    }
    /**
     * @param userId the userId to set
     */
    public void setUserId(long userId) {
        this.userId = userId;
    }
    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }
    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * @return the userDetail
     */
    @OneToOne
    public UserDetail getUserDetail() {
        return userDetail;
    }
    /**
     * @param userDetail the userDetail to set
     */
    public void setUserDetail(UserDetail userDetail) {
        this.userDetail = userDetail;
    }
    /**
     * @return the userLocation
     */
    @OneToOne
    public UserLocation getUserLocation() {
        return userLocation;
    }
    /**
     * @param userLocation the userLocation to set
     */
    public void setUserLocation(UserLocation userLocation) {
        this.userLocation = userLocation;
    }
    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
        result = prime * result + (int) (this.userId ^ (this.userId >>> 32));
        result = prime * result + ((this.userLocation == null) ? 0 : this.userLocation.hashCode());
        result = prime * result + ((this.username == null) ? 0 : this.username.hashCode());
        return result;
    }
    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        User other = (User) obj;
        if (this.password == null) {
            if (other.password != null)
                return false;
        } else if (!this.password.equals(other.password))
            return false;
        if (this.userId != other.userId)
            return false;
        if (this.userLocation == null) {
            if (other.userLocation != null)
                return false;
        } else if (!this.userLocation.equals(other.userLocation))
            return false;
        if (this.username == null) {
            if (other.username != null)
                return false;
        } else if (!this.username.equals(other.username))
            return false;
        return true;
    }
    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "User [userId=" + this.userId + ", username=" + this.username + ", password=" + this.password + ", userLocation=" + this.userLocation + "]";
    }

}
